﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Base;
using Model.Ad;
using DAL.Ad;
public partial class M_updateAdInfo : nspBase.MemberBasePge
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!CheckCookies())
        {
            Response.Redirect("../ErrorPage.aspx?Err=0");
            return;
        }
        else
        {
            if (!IsPostBack)
            {
                string md = Request.QueryString["mid"] as string;
                string strWhere = "where 1=1";
                if (md != "" && md != null)
                {
                    strWhere += " and M_ID=" + md;
                }
                MemberInfo meb = new MemberInfo();
                AdMemberInfo adm = meb.GetModelMemberAdInfo(strWhere);
                this.TxB_Adrees.Text = adm.M_Adrees;
                this.TxB_Image.Text = adm.MImageAdrees;
                this.TxB_word.Text = adm.MLeter;
                this.TxB_Day.Text = adm.MDay.ToString();
                this.txt_AdMName.Text = adm.Ad_MemberInfo_Name.ToString();
            }
            btn_confim.Attributes.Add("onclick", "return UserAd();");
            Btn_upload.Attributes.Add("onclick", "return di();");
        }
    }
    protected void btn_confim_Click(object sender, EventArgs e)
    {
        string md = Request.QueryString["mid"] as string;
        int mid = Convert.ToInt32(md);
        AdMemberInfo adm = new AdMemberInfo();
        adm.M_Adrees = this.TxB_Adrees.Text.ToString().Trim();
        adm.MImageAdrees = this.TxB_Image.Text.ToString().Trim();
        adm.MDay = Convert.ToInt32(this.TxB_Day.Text.ToString().Trim());
        adm.MLeter = this.TxB_word.Text.ToString().Trim();
        adm.Ad_MemberInfo_Name = this.txt_AdMName.Text.ToString().Trim();
        MemberInfo mi = new MemberInfo();
        mi.UpdateMemberAdInfo(mid, adm);
        ShowMessage("修改成功", "Advertisement/M_SelectAd.aspx");
    }

    #region 上传图片
    protected void Btn_up_Click(object sender, EventArgs e)
    {
        Base.Core.WebConfig web = new Base.Core.WebConfig();
        string imgsFolder = web.ImgFolder;
        string datatime = System.DateTime.Now.ToString("yyyyMMddHHmmssffff");
        string strDay = System.DateTime.Now.ToString("yyyyMM");
        if (this.upfile_href.HasFile)
        {
            string fileName = this.upfile_href.FileName;
            string fileExition = System.IO.Path.GetExtension(fileName).ToLower();
            string de = "|.gif|.png|.jpeg|.jpg";
            string path = HttpContext.Current.Server.MapPath("~/" + imgsFolder+strDay);
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }
            if (fileName == "")
            {
                Response.Write("<script>alert('请选择上传的图片');</script>");
                return;
            }
            if (de.IndexOf(fileExition) > 0)
            {
                string NewFileName = "/" + datatime + fileExition;
                this.upfile_href.PostedFile.SaveAs(path + NewFileName);
                this.TxB_Image.Text = Base.BasePage.Config.WebURL + imgsFolder + NewFileName;
            }
            else
            {
                Response.Write("<script>alert('上传图片格式错误');</script>");
            }

        }
    }
    #endregion
}
